package com.frombottom2top.hexdefence.towers;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.RectF;

import com.frombottom2top.hexdefence.constant.Constants;

import java.io.Externalizable;
import java.util.ArrayList;

import com.frombottom2top.hexdefence.impleclass.Tower;
import com.frombottom2top.hexdefence.impleclass.Monster;
import com.frombottom2top.hexdefence.bullet.BulletList;
import com.frombottom2top.hexdefence.utils.LBX;
import com.frombottom2top.hexdefence.view.GameSurfaceView;

/**
 * Created by Administrator on 2016/6/2.
 */
public class Tower_Shell implements Tower,Externalizable {
    boolean flag = true;//标志位
    public int currentPrice = Constants.TOWER1CURRENTPRICE[0];//当前炮台价格
    float x;//炮台中心点坐标
    float y;//炮台中心点坐标
    float shotR=Constants.TOWER1_R[0];//炮台射击半径
    public Bitmap bitmap;//炮台图片
    public GameSurfaceView mv;//GameSurfaceView的引用
    public Paint paint;//画笔引用
    public ArrayList<Monster> master_list;//怪物列表
    float yAngle;//炮台旋转角度
    public BulletList bulletList = new BulletList();//子弹列表
    int limitCount = 20;//子弹发射间隔时间
    public int[] rowCol = new int[2];//炮台的行和列
    public Bitmap all;
    public int currentState = 1;//当前炮台级数
    boolean playflash = false;//升级炮台标志位
    float shanXingAngle = 0;
    //实现成员变量代码

    public Tower_Shell(){};//无参构造器与有参构造器
    public Tower_Shell(float x,float y,Bitmap bitma有参构造器p,GameSurfaceView mv){
        super();
        this.x = x;//炮塔中心点坐标
        this.y = y;//炮塔中心点坐标
        rowCol = LBX.getRowcol(x,y);//炮塔行和列数组
        this.bitmap = Bitmap.createBitmap(bitmap, 0,0,48,48);//初始化图片
        this.all = bitmap;//初始化升级图片
        this.mv = mv;//初始化引用
        paint = mv.paint;//初始化画笔
        master_list = mv.master_list;//初始化怪物列表
    }
    //实现有参构造器和无参构造器

    public void draw(Canvas canvas){
        Matrix m1 = new Matrix();//初始化矩阵
        m1.setTranslate(x-bitmap.getWidth()/2,y-bitmap.getHeight()/2);//矩阵平移
        m1.preRotate(yAngle,bitmap.getWidth()/2,bitmap.getHeight()/2);//矩阵旋转
        canvas.drawBitmap(bitmap, m1,null);//绘制炮台
        bulletList.draw(canvas);//绘制子弹
        if (playflash){//如果播放升级动画
            paint.setColor(Color.WHITE);//设置画笔颜色
            paint.setAlpha(180);//设置画笔透明度
            paint.setStyle(Paint.Style.FILL_AND_STROKE);//设置画笔风格
            RectF ova12 = new RectF(x-bitmap.getWidth()/2+5,y-bitmap.getHeight()/2+5,x+bitmap.getWidth()/2-5,y+bitmap.getHeight()/2-5);//设置检测矩形
            canvas.drawArc(ova12, 200,shanXingAngle,true,paint);//画扇形
        }
    }
}